Skip to content

Conversation

ldursw
Copy link
Contributor

@ldursw ldursw commented Jan 22, 2024

This PR fixes a compiler warning when compiling with -O3. There's no bounds check in pauseChannel, which causes this warning. Adding the bounds check fixes the warning.

framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp: In member function 'void HardwareTimer::pauseChannel(uint32_t)':
framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:203:31: warning: array subscript 4 is above array bounds of 'TimerModes_t [4]' [-Warray-bounds]
  203 |   if (_ChannelMode[channel - 1] == TIMER_INPUT_FREQ_DUTY_MEASUREMENT) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
In file included from framework-arduinoststm32\cores\arduino\stm32/analog.h:45,
                 from framework-arduinoststm32\cores\arduino/board.h:8,
                 from framework-arduinoststm32\cores\arduino/wiring.h:40,
                 from framework-arduinoststm32\cores\arduino/Arduino.h:36,
                 from framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:26:
framework-arduinoststm32\cores\arduino/HardwareTimer.h:188:19: note: while referencing 'HardwareTimer::_ChannelMode'
  188 |     TimerModes_t  _ChannelMode[TIMER_CHANNELS];
      |                   ^~~~~~~~~~~~
framework-arduinoststm32\libraries\SrcWrapper\src\HardwareTimer.cpp:203:31: warning: array subscript 4 is above array bounds of 'TimerModes_t [4]' [-Warray-bounds]
  203 |   if (_ChannelMode[channel - 1] == TIMER_INPUT_FREQ_DUTY_MEASUREMENT) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~^
framework-arduinoststm32\cores\arduino/HardwareTimer.h:188:19: note: while referencing 'HardwareTimer::_ChannelMode'
  188 |     TimerModes_t  _ChannelMode[TIMER_CHANNELS];
      |                   ^~~~~~~~~~~~

@fpistm fpistm added the fix 🩹 Bug fix label Jan 23, 2024
@fpistm fpistm added this to the 2.8.0 milestone Jan 23, 2024
@fpistm fpistm self-requested a review January 23, 2024 09:03
@fpistm
Copy link
Member

fpistm commented Jan 23, 2024

Hi @ldursw
thanks for the PR.

@fpistm fpistm merged commit de1e1c5 into stm32duino:main Jan 23, 2024
@ldursw ldursw deleted the patch-1 branch January 23, 2024 15:49
tadtruex pushed a commit to TadAtThayer/Arduino_Core_STM32 that referenced this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 🩹 Bug fix
Projects
Development

Successfully merging this pull request may close these issues.

2 participants